{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-10-29T06:22:48.330936200Z",
     "start_time": "2023-10-29T06:22:48.308009900Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'set'>\n",
      "{'a', 'c', 'b'}\n"
     ]
    }
   ],
   "source": [
    "set_list = {\"a\",\"b\",\"c\"}\n",
    "print(type(set_list))\n",
    "print(set_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'a', 'b'}\n"
     ]
    }
   ],
   "source": [
    "# 特点：\n",
    "set_list1 = {\"a\",\"a\",\"b\"}  # 元素重复的，试试会不会执行\n",
    "print(set_list1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T06:24:35.085699700Z",
     "start_time": "2023-10-29T06:24:35.060784600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{3, 4}\n"
     ]
    }
   ],
   "source": [
    "A = {1, 2, 3, 4}\n",
    "B = {3, 4, 5, 6}\n",
    "intersection = A & B\n",
    "print(intersection)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T06:41:45.506499Z",
     "start_time": "2023-10-29T06:41:45.493543300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3, 4, 5, 6}\n"
     ]
    }
   ],
   "source": [
    "A = {1, 2, 3, 4}\n",
    "B = {3, 4, 5, 6}\n",
    "union = A | B\n",
    "print(union)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T06:44:14.991726700Z",
     "start_time": "2023-10-29T06:44:14.960392600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2}\n"
     ]
    }
   ],
   "source": [
    "A = {1, 2, 3, 4}\n",
    "B = {3, 4, 5, 6}\n",
    "difference = A - B\n",
    "print(difference)  # 输出: {1, 2}"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T06:45:58.618186500Z",
     "start_time": "2023-10-29T06:45:58.612206300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 5, 6}\n"
     ]
    }
   ],
   "source": [
    "A = {1, 2, 3, 4}\n",
    "B = {3, 4, 5, 6}\n",
    "symmetric_difference = A ^ B\n",
    "print(symmetric_difference)  # 输出: {1, 2, 5, 6}"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T06:47:55.548692100Z",
     "start_time": "2023-10-29T06:47:55.512316900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "A = {1, 2, 3}\n",
    "B = {3, 2, 1}\n",
    "result = A == B\n",
    "print(result)  # 输出: True"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:00:09.180424700Z",
     "start_time": "2023-10-29T08:00:09.169268200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "A = {1, 2, 3}\n",
    "B = {3, 4, 5}\n",
    "result = A != B\n",
    "print(result)  # 输出: True"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:11:07.820423400Z",
     "start_time": "2023-10-29T08:11:07.769504300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "A = {1, 2, 3, 4}\n",
    "result = 3 in A\n",
    "print(result)  # 输出: True"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:12:26.499118100Z",
     "start_time": "2023-10-29T08:12:26.464488100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "A = {1, 2, 3, 4}\n",
    "result = 5 not in A\n",
    "print(result)  # 输出: True"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:13:39.995130800Z",
     "start_time": "2023-10-29T08:13:39.951135400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3, 4}\n"
     ]
    }
   ],
   "source": [
    "my_set = {1, 2, 3}\n",
    "my_set.add(4)\n",
    "print(my_set)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:20:04.576939900Z",
     "start_time": "2023-10-29T08:20:04.543816400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 3}\n"
     ]
    }
   ],
   "source": [
    "my_set = {1, 2, 3}\n",
    "my_set.remove(2)\n",
    "print(my_set)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:21:31.051509800Z",
     "start_time": "2023-10-29T08:21:31.003982500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3}\n"
     ]
    }
   ],
   "source": [
    "my_set = {1, 2, 3}\n",
    "my_set.discard(4)  # 不会引发错误\n",
    "print(my_set)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:23:40.805242800Z",
     "start_time": "2023-10-29T08:23:40.763651500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "my_set1 = {1, 2, 3}\n",
    "my_set2 = {1,2,4,3,5,6,7}\n",
    "print(my_set1.issubset(my_set2))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:29:11.627100100Z",
     "start_time": "2023-10-29T08:29:11.613121700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "set()\n"
     ]
    }
   ],
   "source": [
    "my_set5 = {1,2,3}\n",
    "my_set5.clear()\n",
    "print(my_set5)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:32:04.698193400Z",
     "start_time": "2023-10-29T08:32:04.687230100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3}\n",
      "**********\n",
      "my_set:2440268699616\n",
      "my_copy:2440268702304\n"
     ]
    }
   ],
   "source": [
    "my_set = {1, 2, 3}\n",
    "my_copy = my_set.copy()\n",
    "print(my_copy)\n",
    "print(\"**********\")\n",
    "print(f\"my_set:{id(my_set)}\")\n",
    "print(f\"my_copy:{id(my_copy)}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:35:19.424718900Z",
     "start_time": "2023-10-29T08:35:19.418737Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "set1 = {1, 2, 3}\n",
    "set2 = {1, 2, 3, 4, 5}\n",
    "result = set1.issubset(set2)\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:37:13.392854300Z",
     "start_time": "2023-10-29T08:37:13.385877500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "re = set1 in set2\n",
    "print(re)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:38:42.484393900Z",
     "start_time": "2023-10-29T08:38:42.476642900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "set1 = {1, 2, 3, 4, 5}\n",
    "set2 = {1, 2, 3}\n",
    "result = set1.issuperset(set2)\n",
    "print(result)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:41:07.921318900Z",
     "start_time": "2023-10-29T08:41:07.913132Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "{2, 3, 4, 5}\n"
     ]
    }
   ],
   "source": [
    "my_set = {1, 2, 3, 4, 5}\n",
    "popped_element = my_set.pop()\n",
    "print(popped_element)\n",
    "print(my_set)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:43:07.351024400Z",
     "start_time": "2023-10-29T08:43:07.325439500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3, 4, 5}\n"
     ]
    }
   ],
   "source": [
    "set1 = {1, 2, 3}\n",
    "set2 = {3, 4, 5}\n",
    "set1.update(set2)\n",
    "print(set1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:46:14.134834500Z",
     "start_time": "2023-10-29T08:46:14.125488400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{3}\n"
     ]
    }
   ],
   "source": [
    "set1 = {1, 2, 3}\n",
    "set2 = {3, 4, 5}\n",
    "set1.intersection_update(set2)\n",
    "print(set1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:50:56.722851500Z",
     "start_time": "2023-10-29T08:50:56.701209100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 4, 5}\n"
     ]
    }
   ],
   "source": [
    "set1 = {1, 2, 3}\n",
    "set2 = {3, 4, 5}\n",
    "set1.symmetric_difference_update(set2)\n",
    "print(set1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:56:42.788368500Z",
     "start_time": "2023-10-29T08:56:42.774262500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2}\n"
     ]
    }
   ],
   "source": [
    "set1 = {1, 2, 3}\n",
    "set2 = {3, 4, 5}\n",
    "set1.difference_update(set2)\n",
    "print(set1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T08:59:04.024253300Z",
     "start_time": "2023-10-29T08:59:03.974282400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n",
      "1\n",
      "30\n"
     ]
    }
   ],
   "source": [
    "numbers = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}\n",
    "max_value = max(numbers)\n",
    "min_value = min(numbers)\n",
    "total = sum(numbers)\n",
    "print(max_value)\n",
    "print(min_value)\n",
    "print(total)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T09:08:36.743840500Z",
     "start_time": "2023-10-29T09:08:36.708899600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 9]\n",
      "[9, 6, 5, 4, 3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "numbers = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}\n",
    "sorted_numbers = sorted(numbers)\n",
    "sorted_descending = sorted(numbers, reverse=True)\n",
    "print(sorted_numbers)\n",
    "print(sorted_descending)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T09:11:35.904710700Z",
     "start_time": "2023-10-29T09:11:35.895741500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index 0: cherry\n",
      "Index 1: banana\n",
      "Index 2: apple\n"
     ]
    }
   ],
   "source": [
    "fruits = {\"apple\", \"banana\", \"cherry\"}\n",
    "for index, fruit in enumerate(fruits):\n",
    "    print(f\"Index {index}: {fruit}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-29T09:13:13.195647900Z",
     "start_time": "2023-10-29T09:13:13.173153600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# frozenset"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
